<?php

class apollo_most_reviews_widget extends WP_Widget {
    
    public function __construct() {
        
        parent::__construct(
            
            // ID of widget
            'apollo_most_reviews_widget', 

            // Widget name 
            __('Apollo Most Reviews Widget', 'apollo_most_reviews_widget_domain'), 

            // Widget description
            array( 'description' => __( 'Apollo Most Reviews Widget', 'apollo_most_reviews_widget_domain' ), ) 
        );
    }
        
    // Widget Backend 
    public function form( $instance ) {
       
        ob_start();
        include dirname(__FILE__). '/admin.php';
        $html = ob_get_contents();
        ob_end_clean();
        echo $html;
    }
	
    // Updating widget replacing old instances with new
    public function update( $new_instance, $old_instance ) {
        
        $instance = array();
        $instance['title']                  = ! empty( $new_instance['title'] ) ? strip_tags( $new_instance['title'] ) : '';
        return $instance;
    }
    
    /**
     * Creating widget front-end
     * This is where the action happens
     */
    public function widget( $args, $instance ) {
        
        ob_start();
        include dirname(__FILE__). '/frontend.php';
        $html = ob_get_contents();
        ob_end_clean();
        echo $html;
    }
    
}  